var api = require("@/common/api.js");

export default {
	data() {
		return {
			backinnerHTML: "",
			infoData: '',

			pageParam: {}
		};
	},
	created() {
		this.infoData = this.api.cache("infoData");
		// this.api.cache("token", '7509d8e1fe06b73bb77d0b8998a20d44')
	},
	methods: {
		back() {
			uni.navigateBack({});
		},
		get_lists(callback) {
			var this_ = this;

			api.get(this.lists_url, this.param).then(
				function(data) {
					this_.pageParam = data.data.pages

					this_.items =
						this_.param.page == 1 ?
						data.data.list :
						this_.items.concat(data.data.list);
					// console.log(this_.param.page==data.data.last_page)
					this_.more =
						this_.param.page < data.data.pages.end ? "more" : "noMore";

					if (data.code != 0 && callback) {
						callback && callback(data);
					}
				},
				function(err) {
					console.log("读取文件失败了", err); //对应上面的reject
				}
			);
		},
		go(sa) {
			// if(sa=="/pages/user/xxzq"){
			// 	this.api.alert("暂未开通");
			// 	return
			// }
			this.api.obj.navigateTo({
				url: sa,
			});
		},
		rgo(url) {
			this.api.obj.redirectTo({
				url: url,
			});
		},
		gg_go(url, id) {
			if (url) {
				if (url == "kefu") {
					return;
				}
				if (~url.search(/teb/)) {
					this.api.obj.switchTab({
						url: url,
					});
				} else {
					this.api.obj.navigateTo({
						url: url + id,
					});
				}
			}
		},
		gx_user(info) {
			return new Promise((resove, reject) => {
				this.api.get("users/0", {
					input: info
				}, "post").then((res) => {
					this.api.get("users/0", {}).then((res) => {
						// this.user  = res.data;
						resove(res);
					});
				});
			});
		},
		ddzt(sa) {
			switch (sa * 1) {
				case 0:
					return {
						name: "待付款", img: "../../static/wfk@2x.png"
					};
					break;
				case 1:
					return {
						name: "待发货", img: "../../static/dfh@2x.png"
					};
					break;
				case 2:
					return {
						name: "配送中", img: "../../static/dsh@2x.png"
					};
					break;
				case 3:
					return {
						name: "已到提货点", img: "../../static/dsh@2x.png"
					};
					break;
				case 20:
					return {
						name: "待评价", img: "../../static/dpj@2x.png"
					};
					break;
				case 30:
					return {
						name: "待分享", img: "../../static/ptz@2x.png"
					};
					break;
				case 200:
					return {
						name: "已完成", img: "../../static/ywc@2x.png"
					};
					break;
				default:
					break;
				case -30:
					return {
						name: "失败", img: "../../static/ptsb@2x.png"
					};
					break;
			}
		},
		ddzt_tz(sa, sa2) {
			switch (sa * 1) {
				case 1:
					return {
						name: "配货中", img: "../../static/dsh@2x.png"
					};
					break;
				case 2:
					return {
						name: "待收货", img: "../../static/dsh@2x.png"
					};
					break;
				case 3:
					if (sa2 == 1) {
						return {
							name: "待送货",
							img: "../../static/dsh@2x.png"
						};
					} else {
						return {
							name: "待提货",
							img: "../../static/dsh@2x.png"
						};
					}
					break;

				case 20:
					return {
						name: "待用户评价", img: "../../static/ywc@2x.png"
					};
					break;
				case 200:
					return {
						name: "已完成", img: "../../static/ywc@2x.png"
					};
					break;
			}
		},
		ddzt_hys(sa) {
			switch (sa * 1) {
				case 1:
					return {
						name: "接单中", img: "../../static/dsh@2x.png"
					};
					break;
				case 2:
					return {
						name: "进行中", img: "../../static/dsh@2x.png"
					};
					break;
				case 20:
					return {
						name: "待用户评价", img: "../../static/ywc@2x.png"
					};
					break;
				case 200:
					return {
						name: "已完成", img: "../../static/ywc@2x.png"
					};
					break;
			}
		},
		shijian(fmt, date, san) {
			let ret;
			const opt = {
				"Y+": date.getFullYear().toString(), // 年
				"m+": (date.getMonth() + 1).toString(), // 月
				"d+": (date.getDate() + san).toString(), // 日
				"H+": date.getHours().toString(), // 时
				"M+": date.getMinutes().toString(), // 分
				"S+": date.getSeconds().toString(), // 秒
				// 有其他格式化字符需求可以继续添加，必须转化成字符串
			};
			for (let k in opt) {
				ret = new RegExp("(" + k + ")").exec(fmt);
				if (ret) {
					fmt = fmt.replace(
						ret[1],
						ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, "0")
					);
				}
			}
			return fmt;
		},
		fuzhi(v) {
			uni.setClipboardData({
				data: v,
			});
		},
		tupian(imgs, int, type) {
			//判断是不是视频
			if (imgs[int].video) {
				this.go("/pages/gg/shiping?url=" + imgs[int].video);
				return;
			}

			let tps = [];
			imgs.map((res) => {
				if (type) {
					tps.push(res.path);
				} else {
					tps.push(res.img);
				}
			});
			api.obj.previewImage({
				urls: tps,
				current: int
			});
		},
		dianhua(sa) {
			uni.makePhoneCall({
				phoneNumber: sa, //仅为示例
			});
		},
		fx_tz(res) {
			if (!res.user.nick_name) {
				uni.navigateTo({
					url: "/pages/user/shouquan?lx=" + res.lx,
				});
				return;
			}
			if (res.lx == 1) {
				//lx=0  不用管  1跳转代理商   2跳转花艺师申请
				uni.navigateTo({
					url: "/pages/shangcheng/cwdl?id=5",
				});
			}
			if (res.lx == 2) {
				//lx=0  不用管  1跳转代理商   2跳转花艺师申请
				uni.navigateTo({
					url: "/pages/huayishi/hyssq",
				});
			}
			//截取第一个字符如果是p开头就是跳转到产品
			if (res.lx.substring(0, 1) == "b") {
				uni.navigateTo({
					url: "/pages/shangcheng/cpxq?id=" + res.lx.substring(1),
				});
			}
		},
		getMore(e) {
			console.log(this.param.page, this.pageParam.end);
			if (this.param.page < this.pageParam.end) {
				this.param.page++;
				this.get_lists();
			}
		},
	},
};